package top.yeyusmile.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import top.yeyusmile.common.RobotConfig;

import java.util.HashSet;
import java.util.Set;

/**
 * @author 夜雨
 * @Web www.yeyusmile.top
 * @date 2022/3/17 20:03
 */
@Service
public class BlackWordServiceImpl implements BlackWordService {

    @Autowired
    private RobotConfig config;

    //禁言群号集合
    private Set<Long> banSet = new HashSet<>();


    public void addBanGroupID(Long gid){
        banSet.add(gid);
    }

    /**
     * 是否禁言
     * @param gid
     * @return
     */
    public boolean isBan(Long gid){
        boolean ret = false;
        for (Long id : banSet) {
            if (gid.equals(id)) {
                ret = true;
                break;
            }
        }
        return ret;
    }

    /**
     *清空禁言列表
     *
     */
    public void clearBanSet(){
        banSet.clear();
    }

  //  @Autowired
 //   private SendMsgService sendMsgService;

    @Override
    public boolean isBlackWord(String str) {
        if (str != null && !"".equals(str)) {
            if (config.getBlackWord() != null &&
                    config.containBlackWord(str)) {
                return true;
            } else {
                return false;
            }
        }
        return false;
    }
}
